package d1_arrays;
//自定义排序规则方式一: 让对象所在的类实现比较规则接口Comparable, 重写compareTo
public class Student implements Comparable<Student> {
    private String name;
    private int age;
    private char sex;
    private double height;

    public Student() {
    }

    public Student(String name, int age, char sex, double height) {
        this.name = name;
        this.age = age;
        this.sex = sex;
        this.height = height;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex=" + sex +
                ", height=" + height +
                '}' + "\n";
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public char getSex() {
        return sex;
    }

    public void setSex(char sex) {
        this.sex = sex;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    //指定大小规则
    //比较这: this
    //被比较者: o
    @Override
    public int compareTo(Student o) {
        /**
         * 官方规定:
         * 如果您认为左边大于右边, 请返回正整数.
         * 如果您认为左边小于右边, 请返回负正数
         * 如果您认为左边等于右边, 请返回0
         * 只要这么干,就是升序排序(反过来就是降序排序)
         */
        /*if (this.age > o.age){
            return 1;
        }else if (this.age < o.age){
            return -1;
        }
        return 0;*/
        //其实可以一句达成上面的目的
        //return this.age - o.age;
        return o.age - this.age;//降序
    }
}
